package com.线程;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.locks.ReentrantLock;

public class CyclicBarrier信号 {


    static CyclicBarrier cyclicBarrier = new CyclicBarrier(100);
    public static void main(String[] args) {


        T2 t = new T2(cyclicBarrier);
        for(int i= 0 ; i <100;i++){

            new Thread(t).start();
        }

    }
}


class T2  implements  Runnable{



    CyclicBarrier cyclicBarrier;


    public T2(CyclicBarrier cyclicBarrier) {
        this.cyclicBarrier = cyclicBarrier;
    }

    @Override
    public void run() {


        try {



            System.out.println(Thread.currentThread().getName()+"进入方法");

            Thread.sleep(1000);
            System.out.println(Thread.currentThread().getName()+"等待线程信号全部通过");


            cyclicBarrier.await();


            System.out.println("全部已通过");

        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }


    }
}